package com.yuzhihao.writejvm.clazz;

import com.yuzhihao.writejvm.format.ClassFormatEnum;
import com.yuzhihao.writejvm.format.PrintFormat;
import com.yuzhihao.writejvm.read.Parse;
import lombok.Data;
import lombok.extern.log4j.Log4j2;

import java.io.DataInputStream;
import java.io.IOException;

/**
 * 小版本
 *
 * @author yzh
 * @date 2021年11月29日19:14:35
 */
@Data
@Log4j2
public class MinorVersion implements Parse {

    private ClassFormatEnum cfe = ClassFormatEnum.minor_version;

    private String minor;


    @Override
    public void parse(DataInputStream dis, ClassInfo ci) {
        try {
            this.minor = String.valueOf(Parse.byteToInt(cfe.getB(), dis));
        } catch (IOException e) {
            log.error(e);
        }

        this.out(ci);
    }

    public void out(ClassInfo ci) {
        ci.setMinor_version(this);
    }

    @Override
    public String toString() {
        return PrintFormat.EMPTY + "minor version：" + this.minor + System.lineSeparator();
    }
}
